package Junit;

import static org.junit.Assert.*;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.test.context.ContextConfiguration;

import de.edb.dao.AbstractDataAccessTest;
import de.edb.dao.DaoException;
import de.edb.dao.LocationDao;
import de.edb.model.Artist;
import de.edb.model.Location;


public class LocationJunit extends AbstractDataAccessTest{

	private static final int lid = 12; //set location id for unit tests
	private LocationDao ldao;
	
	public void setUserService(LocationDao ldao)
	{
		this.ldao = ldao;  
	}
	
	@Test
	public void testFindById()
	{
		Location location = this.ldao.findById(lid);
		int i = location.getId();
		assertEquals(lid, i);
	}
	
	@Test
	public void testCreate()
	{
//		String location = "JunitTestLocation";
//		ldao.create(location);		
//		assertEquals(1, ldao.findByName(location).size());
	}
	
	@Test
	public void testFindAll()
	{
		List<Location> location = ldao.findAll();
		int i = location.size();
		assertEquals(this.ldao.findAll().size(),i);
	}
	
	@Test
	public void testFindByName()
	{
		List<Location> location = this.ldao.findAll(); 
		assertTrue(location.containsAll(this.ldao.findByName("JunitTestLocation")));
	}
	
	@Test
	public void testSave()
	{
//		Location location = this.ldao.findById(lid);
//		//location.setId(lid);
//		//location.setCreated(created)
//		location.setDescription("JunitTest");
//		location.setOrt("JunitTest");
//		location.setPlz("94469");
//		location.setStrasse("JunitTest");
//		ldao.save(location);
//		assertEquals(1, ldao.findByName("JunitTestLocation").size());		
	}
	
	@Test
	public void testDelete() throws DaoException
	{
//		SessionFactory sessionFactory = this.ldao.getSessionFactory();
//		Session session = sessionFactory.getCurrentSession();
//		
//		Location location = this.ldao.findById(lid);			
//		
//		ldao.delete(location);
//		session.flush();
//		assertEquals(0, ldao.findByName("JunitTestLocation").size());
		
	}
			
}